package com.qmq.app.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.qmq.app.annotation.Login;
import com.qmq.app.entity.IntroduceEntity;
import com.qmq.app.service.QmqIntroduceService;
import com.qmq.common.utils.Constant;
import com.qmq.common.utils.R;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/app")
public class AppQmqIntroduceController {

    @Resource
    private QmqIntroduceService introduceService;

    @Login
    @GetMapping("/introduce/getByType/{type}")
    @ApiOperation("根据类型获取公司介绍,COMPANY:公司简介,ITEM:项目简介")
    public R getByType(@PathVariable("type") String type) {
        return R.ok().put("data", introduceService.getByType(type));
    }

    @Login
    @PostMapping("/introduce/add")
    @ApiOperation("添加介绍")
    public R addIntroduce(@RequestBody IntroduceEntity dto) {
        introduceService.add(dto);
        return R.ok("添加数据成功");
    }

    @Login
    @GetMapping("/introduce/get/{id}")
    public R get(@PathVariable("id") Long id) {
        return R.ok().put("data", introduceService.getOne(Wrappers.<IntroduceEntity>lambdaQuery()
                .eq(IntroduceEntity::getId, id)
                .last(Constant.SEARCH_ONE)));
    }

    @Login
    @PostMapping("/introduce/update")
    public R update(@RequestBody IntroduceEntity dto) {
        introduceService.updateByDto(dto);
        return R.ok("更新数据成功");
    }

    @Login
    @GetMapping("/introduce/delete/{id}")
    public R delete(@PathVariable("id") Long id) {
        introduceService.delete(id);
        return R.ok("删除数据成功");
    }
}
